﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Caculator {
	class Complex {
		#region Fields
		private double im;
		private double re;
		#endregion
		#region Properties
		public double Im {
			get {
				return this.im;
			}
			set {
				this.im = value;
			}
		}
		public double Re {
			get {
				return this.re;
			}
			set {
				this.re = value;
			}
		}
		#endregion
		#region Methods
		public Complex() {
			this.Im = 0;
			this.Re = 0;
		}
		public static Complex operator +(Complex _a, Complex _b) { 
			Complex rv = new Complex();
			rv.Im = _a.Im + _b.Im;
			rv.Re = _a.Re + _b.Re;
			return rv;
		}
		public static Complex operator -(Complex _a, Complex _b) {
			Complex rv = new Complex();
			rv.Im = _a.Im - _b.Im;
			rv.Re = _a.Re - _b.Re;
			return rv;
		}
		public static Complex operator *(Complex _a, Complex _b) {
			Complex rv = new Complex();
			rv.Re = _a.Re * _b.Re - _a.Im * _b.Im;
			rv.Im = _a.Re * _b.Im + _a.Im * _b.Re;			
			return rv;
		}
		public static Complex operator /(Complex _a, Complex _b) {
			Complex rv = new Complex();
			double r = _b.Re * _b.Re + _b.Im * _b.Im;
			rv.Re = (_a.Re * _b.Re + _a.Im * _b.Im) / r;
			rv.Im = (_a.Im * _b.Re - _b.Im * _a.Re) / r;
			return rv;
		}
		#endregion

	}
}
